//shellFunctions.h

//prevent multiple includes
#ifndef __CHILDEXEC_H__
#define __CHILDEXEC_H__


#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "tokenizer.h"
#include "linkedList.h"


//define some error macros
#define CHECK_ERROR(function,msg)			\
  if((function)==-1){perror(msg); _exit(EXIT_FAILURE);}

#define ERROR(msg)			\
  perror(msg); _exit(EXIT_FAILURE);

#define PARSE_ERROR(function,msg)		\
  if((function)==-1){perror(msg); _return NULL;}

#define CHECK_ALC_ERROR(var)    \
  if ((var)==NULL){perror("cant alloc"); _exit(EXIT_FAILURE);}



//error strings
#define prompt "kinda-sh> " 
#define writeError "Error writing to standard out"
#define readError "There was an error reading your input"
#define ampError "& may only be placed at end of command"
#define openError "Open file error"
#define closeError "close file error"
#define dupError "Dup file error"
#define execError "exec error"
#define killError "kill error"
#define rdrctError "improper redirection"
#define pipeError "pipe error"
#define forkError "fork error"
#define waitError "error waiting for child"
#define sigactionError "error defining signal handler"
#define shellArgError "Invalid shell arguments found. Expecting < > | & or endline"
#define sigaddError "error adding signal to set"
#define tcError "error setting terminal control"

//shellFlags;
  /* store flags that indicate shell commands 
     option is used to supplement this
     
    | 0 | 1  | 2  |  3 |  4    |  5 | 6 | 
      &   fg   bg    |    jobs     >   <  
  */
  /*options:
    |  0  |  1  |   2  |  
      >fd   <fd   jobs #
   */
//flags
#define RUNBG 0
#define FG 1
#define BG 2
#define PIPE 3
#define JOBS 4
#define REDOUT 5
#define REDIN 6
//options
#define OUTFD 0
#define INFD 1
#define JOBID 2

//for storing pgids
//didnt know how else to store int as void
typedef struct ch{
  int pgid;
}CHILD;

/**
 * parses input, sets flags to 1 if shell args found, options used to supplement shell args
 * 
 */
LIST * parseInput(char* input, int *shellFlags, int *option);

//set terminal control, takes pgid
//critical section not interrupted by siggtin and sigttou


//print char** to std out
void printStringArray(char **array, char delimiter);

//simple string euqaility function, loops char by char
int strEquals(char* string1, char* string2);
#endif
